package com.zzc.alfred.entity.web;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zzc.alfred.entity.service.search.ProductSearchService;
import com.zzc.alfred.entity.web.view.CrawlProductView;
import com.zzc.alfred.entity.web.view.ProductBusinessView;

/**
 * 实体框架对外服务web接口
 * 
 * @author famous
 *
 */
@RestController
public class EntityController {

	private Logger logger = Logger.getLogger(EntityController.class);

	// 提供商品检索
	@RequestMapping(value = "productSearch", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody List<CrawlProductView> productSearch(@RequestParam(value = "ak", required = true) String ak,
			@RequestParam(value = "keyWord", required = true) String keyWord,
			@RequestParam(value = "curPage", required = false) Integer curPage,
			@RequestParam(value = "pageSize", required = false) Integer pageSize) {
		logger.info("ak:" + ak + "##curPage" + curPage + "##pageSize" + pageSize + "keyWord" + keyWord);
		ProductSearchService searchService = new ProductSearchService();
		List<CrawlProductView> list = searchService.searchPageByAfter(keyWord, curPage, pageSize);
		return list;
	}

	/**
	 * 查询价格 & 详细地址
	 * 
	 * @param ak
	 * @param pid
	 * @param keyWord
	 * @return
	 */
	@RequestMapping(value = "getProductPriceAndUrl", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	public @ResponseBody ProductBusinessView getProductPrice(@RequestParam(value = "ak", required = true) String ak,
			@RequestParam(value = "pid", required = true) String pid, @RequestParam(value = "keyWord") String keyWord) {
		logger.info("ak:" + ak + "##pid" + pid + "keyWord" + keyWord);
		ProductSearchService searchService = new ProductSearchService();
		return searchService.getPriceAndUrl(pid);
	}
}
